<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<style>
</style>
<div class="col-sm-12 animated fadeInRight">
	<div class="mail-box-header">
		<div class="pull-right tooltip-demo">
			<!-- <a href="mailbox.html" class="btn btn-white btn-sm" data-toggle="tooltip" data-placement="top" title="存为草稿"><i class="fa fa-pencil"></i> 存为草稿</a>-->
			<a onclick="javascript:history.go(-1);" class="btn btn-danger btn-sm"
				data-toggle="tooltip" data-placement="top" title="放弃"><i
				class="fa fa-times"></i> 返回</a>
		</div>
		<h2>文章编辑</h2>
	</div>
	<div class="mail-box">
		<div class="mail-body">
			<form class="form-horizontal" method="get">
				<div class="form-group col-md-6">
					<label class="col-sm-2 control-label">文章标题：</label>
					<div class="col-sm-10">
						<input id="title" type="text" value="${art.title}" class="form-control" placeholder="请填写文章标题">
					</div>
				</div>
				<div class="form-group  col-md-6">
					<label class="col-sm-2 control-label">小标题：</label>
					<div class="col-sm-10">
						<input id="subTitle" type="text" class="form-control" value="${art.subTitle}"
							placeholder="请填写小标题">
					</div>
				</div>
				<div class="form-group  col-md-6">
					<label class="col-sm-2 control-label">缩略图：</label>
					<div class="col-sm-10">
						<input id="subImg" type="file" class="form-control" value="">
					</div>
				</div>

				<div class="form-group  col-md-6">
					<label class="col-sm-2 control-label">文章栏目：</label>
					<div class="col-sm-10">
						<select id="type" class="form-control">
							<option value="question">搬家答疑</option>
						</select>
					</div>
				</div>

				<div class="form-group  col-md-6">
					<label class="col-sm-2 control-label">关键字：</label>
					<div class="col-sm-10">
						<input id="keywords" type="text" class="form-control" value="${art.keyWords}" placeholder="手动填写用   ,  分开">
					</div>
				</div>

				<div class="form-group  col-md-6">
					<label class="col-sm-2 control-label">文章标签：</label>
					<div class="col-sm-10">
						<input id="tag" type="text" class="form-control" value="${art.tag}" placeholder="手动填写用   ,  分开">
					</div>
				</div>

				<div class="form-group  col-md-6">
					<label class="col-sm-2 control-label">内容摘要：</label>
					<div class="col-sm-10">
						<textarea id="subContent" class="form-control" placeholder="请填写内容摘要，不填写系统自动获取前80个字符">${art.subContent}</textarea>
					</div>
				</div>
				<div class="clearfix"></div>
			</form>
		</div>

		<div class="mail-text h-200">
			<textarea id="content" name="content" style="width:100%;height:500px;">${art.content}</textarea>
			<div class="clearfix"></div>
		</div>
		<div class="mail-body text-right tooltip-demo">
			<a onclick="save(this)" data-id="${art.id}" data-status="1" class="btn btn-sm btn-primary" data-toggle="tooltip" data-placement="top" title="Send">
				<i class="fa fa-save"></i>&nbsp;&nbsp;保存并发布
			</a> 
			<a onclick="save(this)" data-id="${art.id}" data-status="0" class="btn btn-sm btn-primary" data-toggle="tooltip" data-placement="top" title="Send">
				<i class="fa fa-save"></i>&nbsp;&nbsp;保存
			</a> 
			<!-- <a onclick="clear()" class="btn btn-white btn-sm" data-toggle="tooltip" data-placement="top" title="Discard email">
			<i class="fa fa-times"></i>&nbsp;&nbsp;清空
			</a> -->
		</div>
		<div class="clearfix"></div>
	</div>
</div>
<script charset="utf-8" src="<%=basePath %>js/plugins/kindeditor/kindeditor-all-min.js"></script>
<script charset="utf-8" src="<%=basePath %>js/plugins/kindeditor/lang/zh-CN.js"></script>
<script type="text/javascript">
KindEditor.ready(function(K) {
    window.editor = K.create('#content',{
    	uploadJson : '<%=basePath%>/File/uploadPics',
		allowImageUpload : true,
		allowFileManager:false,
		afterUpload: function(){this.sync();}, //图片上传后，将上传内容同步到textarea中
        afterBlur: function(){this.sync();},   ////失去焦点时，将上传内容同步到textarea中
       /*  items : [
            'fontname','fontsize', '|','forecolor', 'hilitecolor','bold', 'italic','underline',
            'removeformat','|', 'justifyleft','justifycenter', 'justifyright','insertorderedlist',
            'insertunorderedlist','|', 'emoticons','link','media','|','image'] */
    });
});
function save(obj){
	var id = $(obj).attr('data-id')
	var title = $('#title').val();
	var file =	document.getElementById("subImg").files[0];
	var keywords = $('#keywords').val();
	var subContent = $('#subContent').val();
	var subTitle = $('#subTitle').val();
	var type = $('#type').val();
	var tag = $('#tag').val();
	var content = $('#content').val();
	var status = $(obj).attr('data-status');
	var formData = new FormData();
	if(!title){
		toastr.error('标题不能为空','标题');
		return false;
	}
	if(!keywords){
		toastr.error('关键字不能为空','关键字');
		return false;
	}
	if(!subTitle){
		toastr.error('小标题不能为空','小标题');
		return false;
	}
	if(!tag){
		toastr.error('文章标签不能为空','标签');
		return false;
	}
	if(!content){
		toastr.error('正文不能为空','正文');
		return false;
	}
	if (file){
		formData.append('file',file);
	}
	formData.append('title',title);
	formData.append('keywords',keywords);
	formData.append('subContent',subContent);
	formData.append('subTitle',subTitle);
	formData.append('type',type);
	formData.append('tag',tag);
	formData.append('status',status);
	formData.append('content',content);
	formData.append('id',id);
	$.ajax({
		url:'<%=basePath%>Article/saveArticle',
		type:'POST',
		dataType:'JSON',
		data:formData,
		contentType: false,
		processData: false,
		success:function(data){
			if (data.code=='200'){
				toastr.success('上传成功','成功');
				window.history.back(-1);
			} else{
				toastr.error(data.message,'失败');
			}
		},
		error:function(){
			toastr.error('网络异常','失败');
		}
	});
}
</script>
